function broadcast(compoentName,eventName,params) {
    this.$children.forEach(child=>{
        const name = child.$options.name;

        if(name===compoentName) {
            child.$emit.apply(child,[eventName].concat(params));
        } else {
            broadcast.apply(child,[compoentName,eventName].concat([params]));
        }
    });
}

export default {
    methods: {
        dispatch(compoentName,eventName,params) {
            let parent = this.$parent || this.$root;
            let name = parent.$options.name;
            while(parent && (!name || name !== compoentName)){
                parent = parent.$parent;

                if(parent) {
                    name = parent.$options.name;
                }
            }

            if(parent) {
                parent.$emit.apply(parent,[eventName].concat(params));
            }
        },
        broadcast(compoentName,eventName,params) {
            broadcast.call(this,compoentName,eventName,params);
        }
    }
}